import { param2Obj } from './utils'

const users = {
  'admin': {
    userInfo: {
      a: '1'
    },
    name: 'Super Admin'
  },
  'editor': {
    userInfo: {
      a: '1'
    },
    name: 'Normal Editor'
  }
}
//路由数据
const routesData = {
  Example: {
    show: true,
    children: {
      Table: true,
      Tree: true
    }
  }
}
const routesData1 = {
  Form: {
    show: true,
    children: {
      Forms: true
    }
  }
}

export default {
  login: res => {
    console.log(res)
    const { userCode } = JSON.parse(res.body)
    const data = users[userCode]

    if (data) {
      return {
        code: 20000,
        data
      }
    }
    return {
      code: 60204,
      message: 'Account and password are incorrect.'
    }
  },
  logout: () => {
    return {
      code: 20000,
      data: 'success'
    }
  },
  routes: (res) => {
    const { system } = JSON.parse(res.body)
    console.log(system)
    return {
      code: 20000,
      data: system == 'system1' ? routesData : routesData
    }
  }
}
